package com.wechat.scheme.response;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "Response" , description = "返回实体")
public class Response<T> {
    private static final int SUCCESS_CODE = 200;
    private static final int FAILURE_CODE = 500;
    private static final String SUCCESS_MSG = "success";
    @ApiModelProperty(value = "返回码:200success;非200fail",name = "code" )
    private int code;
    @ApiModelProperty(value = "返回消息:success;异常message",name = "message" )
    private String message;
    @ApiModelProperty(value = "返回数据",name = "data" )
    private T data;

    public static <T> Response<T> succeed() {
        Response<T> response = new Response();
        response.setCode(SUCCESS_CODE);
        response.setMessage(SUCCESS_MSG);
        return response;
    }

    public static <T> Response<T> succeed(T data) {
        Response<T> response = new Response();
        response.setCode(SUCCESS_CODE);
        response.setMessage(SUCCESS_MSG);
        response.setData(data);
        return response;
    }

    public static <T> Response<T> succeed(T data, String message) {
        Response<T> response = new Response();
        response.setCode(SUCCESS_CODE);
        response.setMessage(message);
        response.setData(data);
        return response;
    }

    public static Response<String> fail(String message) {
        Response response = new Response();
        response.setCode(FAILURE_CODE);
        response.setMessage(message);
        return response;
    }

    public static Response<String> fail(int code, String message) {
        Response response = new Response();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }

    public static Response<String> fail(int code, String message, String data) {
        Response response = new Response();
        response.setCode(code);
        response.setMessage(message);
        response.setData(data);
        return response;
    }

}
